package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.Result;
import com.sky.service.impl.AdminOrderServicelmpl;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags="管理端订单管理")
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {
    @Autowired
    private AdminOrderServicelmpl adminOrderServicelmpl;

    /**
     * 查询各个订单数量的统计
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statis(){
        OrderStatisticsVO orderStatisticsVO=adminOrderServicelmpl.statis();
        return Result.success(orderStatisticsVO);
    }
    /**
     * 查询订单详细
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<Orders> details(@PathVariable("id") Long id) {
        Orders orders = adminOrderServicelmpl.details(id);
        return Result.success(orders);
    }
    /**
     * 取消订单3
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        adminOrderServicelmpl.cancel(ordersCancelDTO);
        return Result.success();
    }
    /**
     * 完成订单
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public  Result complete(@PathVariable Integer id){
        adminOrderServicelmpl.complete(id);
        return Result.success();
    }
    /**
     * 拒单
     */
    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        adminOrderServicelmpl.reject(ordersRejectionDTO);
        return Result.success();
    }
    /**
     * 接单
     */
    //TODO  前端问题？？
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@PathVariable Integer id){
        adminOrderServicelmpl.confirm(id);
        return Result.success();
    }
    /**
     * 派送订单
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派单")
    public Result delivery(@PathVariable Integer id){
        adminOrderServicelmpl.delivery(id);
        return Result.success();
    }

}
